package com.itheima.recommend.controller;

import com.itheima.entity.Result;
import com.itheima.entity.StatusCode;
import com.itheima.recommend.service.RecommendService;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/smartSearch")
public class RecommendController {
    @Autowired
    private RecommendService recommendService;

    @RequestMapping("/initStory")
    public Result initStory() {
        recommendService.init();
        return new Result(true, StatusCode.OK, "初始化顶点表成功");
    }

    @RequestMapping("/addEdge")
    public Result addEdge(@RequestParam("p1") String p1, @RequestParam("p2") String p2) {
        recommendService.addEdge(p1, p2);
        return new Result(true, StatusCode.OK, "添加关系成功");
    }

    @RequestMapping("/smartSearch")
    public Result smartSearch(@RequestParam("keyword") String keyword,
                              @RequestParam(value = "number", required = false) Integer number) {

        List<String> smartKey = recommendService.smartSearch(keyword,number);
        return new Result(true, StatusCode.OK, "猜测成功", smartKey);
    }

}
